﻿using Cxuu.Common;
using Cxuu.Models;
using Cxuu.Service;
using Microsoft.AspNetCore.Mvc;
using PetaPoco;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Cxuu.Web.Home
{
    [Area("Home")]
    public class ListController : Base
    {
        private readonly ArticleService _articleService;
        private readonly ArticleCateService _articleCateService;

        public ListController(ArticleService articleService, ArticleCateService articleCateService)
        {
            _articleService = articleService;
            _articleCateService = articleCateService;
        }

        /// <summary>
        /// 根据栏目内容页列表 分页
        /// </summary>
        /// <param name="id">id = cid</param>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> IndexAsync(int id, int page = 1)
        {
            if (id < 1)
            {
                return Ok("请勿非法输入！");
            }
            ArticleCate cateInfo = await _articleCateService.GetOneAsync(id);
            Page<ViewArticleAndCate> infoList = await _articleService.GetListByCidAsync(id, page, cateInfo.Num);
            ViewBag.cateInfo = cateInfo;
            if (cateInfo.Theme != null)
                return View(cateInfo.Theme,infoList);
            else
                return View(infoList);
        }


    }
}
